//
//  MainMenu.m
//  TestUsingCocos2dAndCocosBuilder
//
//  Created by Ronald Ram on 1/1/13.
//  Copyright 2013 Ronald Ram. All rights reserved.
//

#import "MainMenu.h"
#import "MenuMgr.h"
#import "SceneMgr.h"

#import "CCBReader.h"
#import "CCControlButton.h"

#import "LevelSets.h"
#import "Settings.h"
#import "Credits.h"


@interface MainMenu()
- (void) debugData;
- (void) startUpData;
- (void) didLoadFromCCB;

@end



#pragma mark MainMenu
@implementation MainMenu

/*
- (id) init
{
    if ( self = [super init] )
    {
//        [self startUpData];
    }
    return self;
}
*/

- (void) onPress: (id) sender
{
    CCControlButton *button = (CCControlButton *) sender;
    CCLayer *layer = nil;
    
    //    switch (sender.tag)
    switch (button.tag)
    {
        case LEVEL_SETS:
//            [ [SceneMgr sharedScene] switchLayer: [LevelSets node] ];
            CCLOG(@"LevelSets triggered - Tag: %d", button.tag);
            layer = (CCLayer *) [CCBReader nodeGraphFromFile: @"LevelSets.ccbi"];
            [[SceneMgr sharedScene] switchLayer: layer];
            break;
        case SETTINGS:
//            [ [SceneMgr sharedScene] switchLayer: [Settings node] ];
            CCLOG(@"Settings triggered - Tag: %d", button.tag);
            layer = (CCLayer *) [CCBReader nodeGraphFromFile: @"Settings.ccbi"];
            [[SceneMgr sharedScene] switchLayer: layer];
            break;
        case CREDITS:
//            [ [SceneMgr sharedScene] switchLayer: [Credits node] ];
            layer = (CCLayer *) [CCBReader nodeGraphFromFile: @"Credits.ccbi"];
            [[SceneMgr sharedScene] switchLayer: layer];
            break;
    }
}


#pragma mark Private-Methods
- (void) startUpData
{
//    CCNode *node = [CCBReader nodeGraphFromFile: @"MainMenu.ccbi" owner: self];
//    [self addChild: node];
    
    self.tag = MAIN_MENU;
}

- (void) didLoadFromCCB
{
    [self startUpData];
}

- (void) debugData
{
    CGSize size = [CCDirector sharedDirector].winSize;
    
    //add BG to menu
    CCSprite *bg = [CCSprite spriteWithFile: @"Default@2x.png"];
    bg.position = ccp(size.width * 0.5, size.height * 0.5);
    [self addChild: bg];
    
    //add menu title
    CCLabelTTF *label = [CCLabelTTF labelWithString: @"Main Menu" fontName: @"Noteworthy" fontSize: 56];
    label.position = ccp(size.width / 2, size.height - (size.height * 0.15) );
    [self addChild: label];
    
    //add MenuItem btns
    CCMenuItemFont *item1 = [CCMenuItemFont itemWithString:@"Play" target:self selector:@selector(onPress:)];
    item1.tag = LEVEL_SETS;
    
    CCMenuItemFont *item2 = [CCMenuItemFont itemWithString:@"Settings" target:self selector:@selector(onPress:)];
    item2.tag = SETTINGS;
    
    CCMenuItemFont *item3 = [CCMenuItemFont itemWithString:@"Credits" target:self selector:@selector(onPress:)];
    item3.tag = CREDITS;
    
    //add menuItem(s) to menu
    CCMenu *menu = [CCMenu menuWithItems:item1, item2, item3, nil];
    [menu alignItemsVerticallyWithPadding: 30];
    [menu setColor: ccORANGE];
    
    //add menu to layer
    [self addChild: menu];
    self.tag = MAIN_MENU;
}

@end


/*
//- (void)onEnter
//{
//    [super onEnter];    
//    id action = [CCFadeIn actionWithDuration: 1];
//    for ( id child in self.children)
//    {
//        [child runAction: action];
//    }
//
//}
*/

